Skip to content

Conversation

@ianic
Copy link
Contributor

@ianic ianic commented Jan 4, 2026

This if follow up of #789 adding more examples of how to use lwip with pi pico 2w.

There are udp send/receive and tcp client/server examples here. Readme should help with running examples.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Lint Results

Found 60 issues on changed lines in 16 files:

  • examples/microchip/atsam/src/blinky.zig: 1 issue
  • examples/nordic/nrf5x/build.zig: 1 issue
  • port/stmicro/stm32/src/hals/STM32F103/DMA.zig: 5 issues
  • port/stmicro/stm32/src/hals/STM32F103/adc.zig: 1 issue
  • port/stmicro/stm32/src/hals/STM32F103/i2c.zig: 1 issue
  • port/stmicro/stm32/src/hals/STM32F103/rcc.zig: 1 issue
  • port/stmicro/stm32/src/hals/common/i2c_v2.zig: 1 issue
  • port/stmicro/stm32/src/hals/common/util.zig: 1 issue
  • tools/linter/src/main.zig: 1 issue
  • tools/regz/src/Database.zig: 3 issues
  • tools/regz/src/atdf.zig: 18 issues
  • tools/regz/src/embassy.zig: 2 issues
  • tools/regz/src/gen.zig: 7 issues
  • tools/regz/src/output_tests.zig: 1 issue
  • tools/regz/src/svd.zig: 15 issues
  • tools/regz/src/xml.zig: 1 issue
ℹ️ Additional issues on unchanged lines
The following 63 issue(s) exist but are not on lines changed in this PR:

build-internals/build.zig:121: Suggestion: Rename `Cpu` to `CPU`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
build.zig:325: TODO style comments need to have a linked microzig issue on the same line.
build.zig:8: Suggestion: Rename `Cpu` to `CPU`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
core/src/cpus/cortex_m.zig:850: Suggestion: Rename `IrqHandlerFn` to `IRQ_HandlerFn`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
core/src/cpus/cortex_m.zig:879: Suggestion: Rename `HardFault_name` to `HardFaultName`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
core/src/cpus/cortex_m.zig:880: Suggestion: Rename `BusFault_name` to `BusFaultName`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
core/src/cpus/cortex_m.zig:881: Suggestion: Rename `MemManageFault_name` to `MemManageFaultName`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
core/src/cpus/cortex_m.zig:882: Suggestion: Rename `UsageFault_name` to `UsageFaultName`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/build.zig:25: TODO style comments need to have a linked microzig issue on the same line.
examples/raspberrypi/rp2xxx/src/net/lwip/net.zig:534: Suggestion: Rename `IPFormatter` to `IP_Formatter`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/build.zig:18: TODO style comments need to have a linked microzig issue on the same line.
examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig:11: Suggestion: Rename `AdvancedADC` to `Advanced_ADC`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig:18: Suggestion: Rename `ADC_pin1` to `ADC_Pin1`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig:19: Suggestion: Rename `ADC_pin2` to `ADC_Pin2`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig:25: Suggestion: Rename `AdcData` to `ADC_Data`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig:19: Suggestion: Rename `AdvancedADC` to `Advanced_ADC`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig:27: Suggestion: Rename `ADC_pin1` to `ADC_Pin1`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig:28: Suggestion: Rename `ADC_pin2` to `ADC_Pin2`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig:29: Suggestion: Rename `ADC_pin3` to `ADC_Pin3`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/raspberrypi/rp2xxx/src/hal/dma.zig:120: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/boards/STM32L476DISCOVERY.zig:27: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/boards/STM32L476DISCOVERY.zig:8: Suggestion: Rename `LcdRam` to `LCD_RAM`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/boards/STM32L476DISCOVERY.zig:20: Suggestion: Rename `Lcd` to `LCD`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/generate.zig:256: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103.zig:24: Suggestion: Rename `Reset_Reason` to `ResetReason`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/STM32F103/adc.zig:374: Suggestion: Rename `AdvancedADC` to `Advanced_ADC`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:2: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/rcc.zig:309: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/spi.zig:28: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/uart.zig:1: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F103/uart.zig:2: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/STM32F303/rcc.zig:25: Suggestion: Rename `RccErrorConfig` to `RCC_ErrorConfig`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/i2c_v2.zig:69: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/i2c_v2.zig:80: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/i2c_v2.zig:113: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/i2c_v2.zig:13: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/i2c_v2.zig:21: Suggestion: Rename `TimingSpec_Standard` to `TimingSpecStandard`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/pins_v2.zig:46: Suggestion: Rename `InputGPIO` to `Input_GPIO`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/pins_v2.zig:57: Suggestion: Rename `OutputGPIO` to `Output_GPIO`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/timer_v1.zig:169: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/timer_v1.zig:172: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/timer_v1.zig:24: Suggestion: Rename `ARRModes` to `ARR_Modes`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/timer_v1.zig:112: Suggestion: Rename `CCConfig` to `CC_Config`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/timer_v1.zig:173: Suggestion: Rename `GPTimer` to `GP_Timer`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/timer_v1.zig:542: Suggestion: Rename `PWMChConfig` to `PWM_ChConfig`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/stmicro/stm32/src/hals/common/uart_v3.zig:77: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/uart_v3.zig:79: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/uart_v3.zig:82: TODO style comments need to have a linked microzig issue on the same line.
port/stmicro/stm32/src/hals/common/uart_v3.zig:192: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/clocks.zig:14: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/clocks.zig:150: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/clocks.zig:173: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:703: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:730: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:733: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:752: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:779: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:782: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/atdf.zig:792: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/embassy.zig:436: TODO style comments need to have a linked microzig issue on the same line.
tools/regz/src/embassy.zig:87: Suggestion: Rename `Rcc` to `RCC`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
tools/regz/src/embassy.zig:558: Suggestion: Rename `Item_t` to `Item`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
tools/regz/src/gen.zig:421: TODO style comments need to have a linked microzig issue on the same line.

⚠️ Could not attach inline comments due to an error.

@github-actions github-actions bot dismissed their stale review January 4, 2026 18:23

Updating with new lint results

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Lint Results

ℹ️ Additional issues on unchanged lines
The following 1 issue(s) exist but are not on lines changed in this PR:

examples/raspberrypi/rp2xxx/src/net/lwip/net.zig:534: Suggestion: Rename `IPFormatter` to `IP_Formatter`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.

Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good. Have to review more closely. Fixed up wording and some typoes.

Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Noticed a few more typos/style issues. I'll ask for someone to test.

@tact1m4n3
Copy link
Collaborator

tact1m4n3 commented Jan 7, 2026

I've tested on my pico 2w and there are a couple of things not working. But anyhow, great work. A tcp server on a pico in zig is very nice.

ReleaseSmall crashes with unhandled exception right away for both TCP server and client and maybe also udp

TCP server works perfectly

[2.626838] debug (lwip): netif status callback is_link_up: false, is_up: true, ready: false, ip: 0.0.0.0
[3.967406] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183
[4.990519] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183
[23.008030] debug (main): 2001653c connected
[26.370782] debug (main): 2001653c recv 6 bytes, total: 6 hello
[53.082016] debug (main): 2001653c closed error.EndOfStream

TCP Server Release Fast displays something sus

================ STARTING NEW LOGGER ================
[1.794243] error (cyw43_wifi): unexpected data:
[1.798612] error (cyw43_wifi):   bus: .{ .len = 260, .not_len = 65275, .seq = 33, .cf = .{ .chan = .data, .flags = 0 }, .nextlen = 0, .hdrlen = 30, .flow = 0, .credit = 43, ._reserved = 0 }
[1.815604] error (cyw43_wifi):   bdc: .{ .flags = 32, .priority = 0, .flags2 = 0, .offset = 1 }
[1.824234] error (cyw43_wifi):   data: 01005e0000fb7e2f0e2647bc0800450000d0a7e00000ff116fe6c0a801b2e00000fb14e914e900bcc840000000000006000100000000085f686f6d656b6974045f746370056c6f63616c00000c0001045f686170c015000c0001045f686170045f756470c01a000c00010f5f636f6d70616e696f6e2d6c696e6bc015000c0001075f72646c696e6bc015000c00012441334131394441302d394143422d353036452d413743322d333032444632413233374443c00c00100001c040000c0001000011910019164d617269616ee2809973204d6163426f6f6b2050726fc040
[2.621225] debug (lwip): netif status callback is_link_up: false, is_up: true, ready: false, ip: 0.0.0.0
[3.992137] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183
[5.007359] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183

TCP client (I have a listening netcat server on my computer but it might be an error on my end)

================ STARTING NEW LOGGER ================
[2.576729] debug (lwip): netif status callback is_link_up: false, is_up: true, ready: false, ip: 0.0.0.0
[3.917407] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183
[4.965010] debug (lwip): netif status callback is_link_up: true, is_up: true, ready: true, ip: 192.168.1.183
[22.474065] debug (main): connection closed error.ConnectionAborted

Udp (EDIT: I realized now that this is because I haven't changed join options for my network that doesn't have any security).

[1.792690] error: panic: main() returned error.Cyw43JoinSetSsid
[1.798474] error:   0: 0x1001B305
[1.801620] error:   1: 0x1001F5F5
[1.804698] error:   2: 0x000002F5
[1.807784] error:   3: 0x00000000

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Lint Results

ℹ️ Additional issues on unchanged lines
The following 1 issue(s) exist but are not on lines changed in this PR:

examples/raspberrypi/rp2xxx/src/net/lwip/net.zig:565: Suggestion: Rename `IPFormatter` to `IP_Formatter`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.

@ianic
Copy link
Contributor Author

ianic commented Jan 7, 2026

Thanks @tact1m4n3.

For the tcp_client. Did you enter your host IP address in secrets.zig

// IP address of the desktop host computer.
// Some examples will send to that host.
pub const host_ip = "192.168.190.235";

For udp. That is wifi join fail error. Join sequence is the same as in tcp examples so I expect it to be transient. Do you get it on each retry (restart)?

Unexpected data in tcp server is not the problem. WiFi chip got data packet while still joining network. I should probably just ignore it.

@tact1m4n3
Copy link
Collaborator

tact1m4n3 commented Jan 7, 2026

For the tcp_client. Did you enter your host IP address in secrets.zig

I did.

I am a bit concerned with the crash I got whenever I build in release small. Do you get it as well?

EDIT: I tested udp again after fixing the join configuration and I can send packets to the pico, but I don't receive the echoed packets (on a separate nc instance).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Lint Results

ℹ️ Additional issues on unchanged lines
The following 4 issue(s) exist but are not on lines changed in this PR:

drivers/wireless/cyw43439/ioctl.zig:29: Suggestion: Rename `SdpHeader` to `SDP_Header`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/wireless/cyw43439/ioctl.zig:74: Suggestion: Rename `CdcHeader` to `CDC_Header`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/wireless/cyw43439/ioctl.zig:401: Suggestion: Rename `BssInfo` to `BSS_Info`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/raspberrypi/rp2xxx/src/net/lwip/net.zig:565: Suggestion: Rename `IPFormatter` to `IP_Formatter`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.

@ianic
Copy link
Contributor Author

ianic commented Jan 7, 2026

Thank you for your time.

I was also getting crashes in ReleaseSmall/ReleaseSafe. I located that in a @bitcast line. As I understand there is 32 bit alignment requirement for some instructions. It was hit by unaligned data. Solved that by changing to @memcpy.

udp, and tcp_client works for me. As I understand any incoming traffic to your host from the pico don't work. Is there chance that you have some kind of firewall blocking it.

For the udp, when I send to the pico ip from the host:

echo "message to the pico" | ncat -u 192.168.190.50 9999

i got it echoed when listening on the host:

ncat -ulp 9999

or

nc -u -l -vvv -p 9999

I also see valid udp packets in the Wireshark.

@tact1m4n3
Copy link
Collaborator

Everything works now! It was a problem with my linux desktop when I didn't receive any incoming packets. It worked on another machine.

ianic and others added 14 commits January 8, 2026 11:39
Add tcp namespace; we will have Client and Server. Move root to the
Interface so we can have net in the imports instead of Net.
When reciving clean close should call tcp_close and set connection state
to closed.
It is enough to pass it into init.
with multiple calls of tcp_connect for the same Connection. Prevent that
with setting state to .connecting and aborting pcb in
on_connect (although that can't be reaced now).
Co-authored-by: Grazfather <grazfather@gmail.com>
Co-authored-by: Grazfather <grazfather@gmail.com>
ianic and others added 6 commits January 8, 2026 11:39
They are now in the readme.
Co-authored-by: Grazfather <grazfather@gmail.com>
There is no guarantee that buf has 4 bytes alignment. Is seems that
@bitcast or buf.* requires that alignment.
Avoiding @bitcast and buf.* by using @memcpy.
There are cases when data packet event is received while still not all
join events are raised. This was logged as error but it is just
misleading we can't do nothing about that until application starts
listening for data packets.
Now all arguments are in the single file.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Lint Results

ℹ️ Additional issues on unchanged lines
The following 5 issue(s) exist but are not on lines changed in this PR:

drivers/wireless/cyw43439/ioctl.zig:29: Suggestion: Rename `SdpHeader` to `SDP_Header`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/wireless/cyw43439/ioctl.zig:74: Suggestion: Rename `CdcHeader` to `CDC_Header`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/wireless/cyw43439/ioctl.zig:401: Suggestion: Rename `BssInfo` to `BSS_Info`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/wireless/cyw43439/wifi.zig:103: Suggestion: Rename `ClmLoadControl` to `CLM_LoadControl`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
examples/raspberrypi/rp2xxx/src/net/lwip/net.zig:565: Suggestion: Rename `IPFormatter` to `IP_Formatter`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.

@mattnite
Copy link
Contributor

mattnite commented Jan 8, 2026

Thanks again @ianic, this is freaking awesome

@mattnite mattnite merged commit 7bf488e into ZigEmbeddedGroup:main Jan 8, 2026
56 checks passed
Copper280z pushed a commit to Copper280z/microzig that referenced this pull request Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants